﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NDependActivities;
using KellermanSoftware.CompareNetObjects;

namespace NDependActivitiesTests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class NDependReportReaderTests
    {
        public NDependReportReaderTests()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void GetReportInfo_CollectedReportInfoIsCorrect()
        {
            var reader = new NDependReportReader("NDependMainTailspinToys.xml");
            var reportContainer = reader.GetReportInfo();
            var targetReport = new NDependReportInfo
            {
                NbCqlQueries = 111,
                NbCqlQueriesErrors = 3,
                NbCqlQueriesWarnings = 44,
                NbCriticalRules = 2,
                NbLinesOfCode = 4368,
                NbLinesOfComment = 728,
                NbSourceFiles = 103,
                NClass = 148,
                NILInstruction = 27912,
                NNamespaces = 17,
                NType = 237,
                PercentageComment = 14,
                PercentCodeCoverage = 2.72M,
                PercentPublicType = 92.83M,
                PercentPublicMethod = 83.25M
            };
            var comparer = new CompareObjects();
            Assert.IsTrue(
                comparer.Compare(targetReport, reportContainer.ReportInfo),
                "NDependReportInfo has not been accurately parsed: " + comparer.DifferencesString);
        }

        [TestMethod]
        public void GetReportInfo_CollectedCriticalRulesAreCorrect()
        {
            var reader = new NDependReportReader("NDependMainTailspinToys.xml");
            var reportContainer = reader.GetReportInfo();
            var targetCritialRules = new List<NDependCriticalRuleInfo>
            {
                new NDependCriticalRuleInfo { Name = "Code Quality \\ Methods with too many parameters(NbParameters) - critical" },
                new NDependCriticalRuleInfo { Name = "Code Quality \\ Methods too big (NbLinesOfCode)" }
            };
            var comparer = new CompareObjects();
            Assert.IsTrue(
                comparer.Compare(targetCritialRules, reportContainer.CriticalRules),
                "Critical rules have not been accurately parsed: " + comparer.DifferencesString);
        }
    }
}
